" OS detect
if has("win32") || has("win64") || has("win32unix")
    let g:OS#name = "win"
    let g:OS#win = 1
    let g:OS#mac = 0
    let g:OS#unix = 0
elseif has("mac")
    let g:OS#name = "mac"
    let g:OS#mac = 1
    let g:OS#win = 0
    let g:OS#unix = 0
elseif has("unix")
    let g:OS#name = "unix"
    let g:OS#unix = 1
    let g:OS#win = 0
    let g:OS#mac = 0
endif

" GUI detect
if has("gui_running")
  let g:OS#gui = 1
else
  let g:OS#gui = 0
endif

"==============================================================
""==============================================================
"
""   Vundle插件管理和配置项
"
""==============================================================
"==============================================================
"
""开始使用Vundle的必须配置
set nocompatible
if g:OS#win
  source $VIMRUNTIME/vimrc_example.vim
  source $VIMRUNTIME/mswin.vim
  behave mswin
endif
filetype off

if g:OS#win
  set rtp+=$VIM/vimfiles/bundle/vundle/  
  call vundle#rc('$VIM/vimfiles/bundle/')  
else
  set rtp+=~/.vim/bundle/vundle/
  call vundle#rc()
endif

"=== 使用Vundle来管理Vundle ===
Bundle 'gmarik/vundle'
Bundle 'The-NERD-tree'
imap <F3> <Esc>:NERDTreeToggle<cr>
nmap <F3> :NERDTreeToggle<cr>
Bundle 'Emmet.vim'

"=== 主题 molokai ===
Bundle 'tomasr/molokai'
Bundle 'altercation/vim-colors-solarized'
""设置主题
colorscheme molokai
"set background=dark
"set t_Co=256
"
Bundle 'Auto-Pairs'
Bundle 'matchit.zip'
Bundle 'Tabular'

" Javascript dev
Bundle 'jelera/vim-javascript-syntax'
Bundle 'vim-scripts/JavaScript-Indent'


"=============================================================
"=============================================================
"
"    Vim基本配置
"
"=============================================================
"=============================================================

"关闭vi的一致性模式 避免以前版本的一些Bug和局限
set nocompatible
"配置backspace键工作方式
set backspace=indent,eol,start

let mapleader = ","
let g:mapleader = ","


"显示行号
set number
"设置在编辑过程中右下角显示光标的行列信息
set ruler
"当一行文字很长时取消换行
"set nowrap

"在状态栏显示正在输入的命令
set showcmd

"设置历史记录条数
set history=1000

"设置取消备份 禁止临时文件生成
set nobackup
set noswapfile

"突出现实当前行列、高亮当前行列
set cursorline
hi cursorline guibg=NONE gui=underline
"set cursorcolumn

" Toggle Menu and Toolbar
" @see http://liyanrui.is-programmer.com/articles/1791/gvim-menu-and-toolbar-toggle.html
if g:OS#gui
    set guioptions-=m
    set guioptions-=T
    set go-=r
    set go-=L
    map <silent> <F2> :if &guioptions =~# 'T' <Bar>
            \set guioptions-=T <Bar>
            \set guioptions-=m <bar>
        \else <Bar>
            \set guioptions+=T <Bar>
            \set guioptions+=m <Bar>
        \endif<CR>
endif

" Use Unix as the standard file type
set ffs=unix,dos,mac

" fonts
" @see http://support.microsoft.com/kb/306527/zh-cn
" @see http://www.gracecode.com/archives/1545/
" @see http://blog.xianyun.org/2009/09/14/vim-fonts.html
if g:OS#win
    set guifont=Courier_New:h12:cANSI
    "set guifont=Microsoft_YaHei_Mono:h11:cANSI

    "set guifont=monaco:h11:cANSI
    "set guifont=Consola:h11:cANSI
    "set guifont=DajaVu:h11:cANSI
    "set guifont=Lucida\ Console:h11:cANSI
    "set guifontwide=YouYuan:h11:cGB2312
elseif g:OS#mac
    set guifont=Courier_New:h16
elseif g:OS#unix
endif

" @see http://blog.sina.com.cn/s/blog_46dac66f010006db.html
set ambiwidth=double

""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2

" Format the status line
set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l

" @see :help mbyte-IME
if has('multi_byte_ime')
    highlight Cursor guibg=#F0E68C guifg=#708090
    highlight CursorIM guibg=Purple guifg=NONE
endif

" Encodings
" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf8
set fileencodings=ucs-bom,utf8,cp936,gb18030,big5
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
language messages zh_CN.UTF-8

"设置匹配模式 类似当输入一个左括号时会匹配相应的那个右括号
set showmatch

"设置C/C++方式自动对齐
set autoindent
"set cindent

"开启语法高亮功能
syntax enable
syntax on

"指定配色方案为256色
set t_Co=256

"设置搜索时忽略大小写
set ignorecase

"设置在Vim中可以使用鼠标 防止在Linux终端下无法拷贝
set mouse=a

"设置Tab宽度
set tabstop=2
"设置自动对齐空格数
set shiftwidth=2
"设置按退格键时可以一次删除4个空格
set softtabstop=2
"设置按退格键时可以一次删除4个空格
set smarttab
"将Tab键自动转换成空格 真正需要Tab键时使用[Ctrl + V + Tab]
set expandtab

"设置编码方式
set encoding=utf-8
"自动判断编码时 依次尝试一下编码
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

"检测文件类型
filetype on
"针对不同的文件采用不同的缩进方式
filetype indent on
"允许插件
filetype plugin on
"启动智能补全
filetype plugin indent on

"=========================================================
" Key Mapings
" =======================================================

" Treat long lines as break lines (useful when moving around in them)
map j gj
map k gk

" Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

" Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>

" Reload vimrc
map <silent> <F5> :so %<cr>
